package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.union.cross.CrossUnionProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;

import java.math.BigInteger;

@Cmd(code = Protocol.S_UNION_UPGRADE_CROSS_FROM_CROSS, desc = "商会晋升跨服")
public class UnionUpgradeCrossCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        CrossUnionProto.UnionUpgradeCrossRespMsg respMsg = CrossUnionProto.UnionUpgradeCrossRespMsg.parseFrom(packet.getBytes());

        Property consume = new Property();
        consume.addProperty(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(GameConfig.UNION_UP_COST));
        player.getModule(PreReduceModule.class).restorePreReduce(consume);

        if(respMsg.getRet() == 0){
            player.getModule(CurrencyModule.class).removeCurrency(consume, eLogMoneyType.Union, eLogMoneyType.UnionUpgradeCrossConsume);
        }

        player.sendPacket(Protocol.U_UNION_UPGRADE_CROSS, CrossUnionProto.UnionUpgradeCrossRespMsg.newBuilder().setRet(respMsg.getRet()));
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
